package com.lct.random;

import java.util.Random;
import java.util.Scanner;

public class RandomTest3 {
    //猜数字游戏
    public static void main(String[] args) {


        //创建一个随机数
        Random  r = new Random();
        int number = r.nextInt(100) + 1;
        System.out.println("这个数字是" + number);


        //用户输入一个数字
        Scanner sc = new Scanner(System.in);


        while (true) {
            System.out.println("请输入一个您猜测的数字 1-100");
            int guessNumber = sc.nextInt();

            if(guessNumber > number)
                System.out.println("你猜大了");
            else if (guessNumber < number)
                System.out.println("你猜小了");
            else {
                System.out.println("恭喜你猜对了");
                break;
            }
        }
  }

}
